package org.lan.tree;

/**
 * @author <p><a href="mailto:1728209643@qq.com">XiaoSan</a>
 * @date 2019/11/25 9:28 AM
 */
public class BinarySearchTree {

    TreeNode root;

    public BinarySearchTree(int val) {
        root = new TreeNode(val);
    }

    public void insert(int val) {
        TreeNode p = root;
        TreeNode q = p;
        while (p != null) {
            q = p;
            if (p.val > val) {
                p = p.left;
            } else {
                p = p.right;
            }
        }
        if (q.val > val) {
            q.left = new TreeNode(val);
        } else {
            q.right = new TreeNode(val);
        }
    }

    public TreeNode getRoot() {
        return root;
    }

}
